Hello again, young web developer! Now that you've learned the basics of HTML, let's dive a little deeper and explore the differences between HTML elements and attributes. This tutorial will help you understand the two and how to use them effectively.
<p>This is a paragraph.</p>
Here's a quick recap of some common HTML elements you've already learned:
<h1>
to <h6>
: Heading tags for different sizes of headings.<p>
: Paragraph tag for blocks of text.<a>
: Anchor tag for creating hyperlinks.<img>
: Image tag for inserting images.<ul>
and <ol>
: Unordered (bullet-point) and ordered (numbered) list tags.<tag attribute="value">
.Here are some common HTML attributes:
href
: Used with the <a>
tag to specify the destination URL. Example: <a href="https://www.example.com">Visit Example.com</a>
src
: Used with the <img>
tag to specify the image file location. Example: <img src="image.jpg">
alt
: Used with the <img>
tag to provide a text description of the image. Example: <img src="image.jpg" alt="A cute kitten">
style
: Can be used with most tags to apply CSS (Cascading Style Sheets) styling directly to the element. Example: <p style="color: blue;">This text is blue.</p>
Example 1:
html<a href="https://www.example.com">Visit Example.com</a>
In this example, <a>
is the element (tag) and href
is the attribute. The element creates a hyperlink, and the attribute tells the browser where the link should go.
Example 2:
html<img src="image.jpg" alt="A beautiful sunset">
Here, <img>
is the element (tag), while src
and alt
are attributes. The element is used to display an image, and the attributes tell the browser which image file to use and provide a text description.
style
attribute.href
attribute.src
and alt
attributes.Remember to save your file with the .html extension and open it in a web browser to see your work!
Understanding the difference between HTML elements and attributes is an essential skill for web development. Keep practicing, and soon you'll be a master of HTML!